package com.gxar.quick.ar.server.base.model.protocol;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.gxar.quick.ar.server.base.common.utils.NumberUtils;

import java.io.IOException;
import java.util.Objects;

/**
 * Double数格式化
 *
 * @author zxh
 * @version 1.0
 * @created 2024/01/02.
 */
public class PlainDoubleSerialize extends JsonSerializer<Double> {

    @Override
    public void serialize(Double inputDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (Objects.isNull(inputDouble)) {
            return;
        }

        String format = NumberUtils.formatDouble(inputDouble);
        jsonGenerator.writeString(format);
    }
}
